package com.ysd.lis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.WkQualityType;
import com.ysd.lis.mapper.WkQualityTypeMapper;
import com.ysd.lis.service.WkQualityTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 质量控制类型-体系表 服务实现类
 * </p>
 *
 * @author LiuQi
 * @since 2024-05-06
 */
@Service
public class WkQualityTypeServiceImpl extends ServiceImpl<WkQualityTypeMapper, WkQualityType> implements WkQualityTypeService {

    @Autowired
    WkQualityTypeMapper wkQualityTypeMapper;

    @Override
    public Result getQualityTypeList() {
        LambdaQueryWrapper<WkQualityType> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(WkQualityType::getDelFlag, 0);
        List<WkQualityType> wkQualityTypes = wkQualityTypeMapper.selectList(lambdaQueryWrapper);
        return Result.succ(1, "查询成功！", wkQualityTypes);
    }

    @Override
    public Result addQualityType(WkQualityType wkQualityType) {
        boolean save = this.save(wkQualityType);
        if (save) {
            return Result.succ(1, "插入成功！", save);
        } else {
            return Result.fail("插入失败！");
        }
    }

    @Override
    public Result editQualityType(WkQualityType wkQualityType) {
        boolean save = this.updateById(wkQualityType);
        if (save) {
            return Result.succ(1, "编辑成功！", save);
        } else {
            return Result.fail("编辑失败！");
        }
    }

    @Override
    public Result deleteQualityType(WkQualityType wkQualityType) {
        boolean save = this.removeById(wkQualityType.getId());
        if (save) {
            return Result.succ(1, "删除成功！", save);
        } else {
            return Result.fail("删除失败！");
        }
    }
}
